﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace WellDone
{
    public partial class RestoreEmployeeDialog : ChildWindow
    {
        public RestoreEmployeeDialog()
        {
            InitializeComponent();
        }

        private async void btnOK_Click(object sender, RoutedEventArgs e)
        {
            // Restore the selected person
            Globals.db.EmployeeRecords[cmbNames.SelectedIndex].col_Active = true;
            Globals.db.EmployeeRecords[cmbNames.SelectedIndex].bFilterActive = true;
            await Globals.db.UpdateEmployeeObject(Globals.db.EmployeeRecords[cmbNames.SelectedIndex]);
            Globals.employees.strSelectedName = cmbNames.SelectedValue.ToString();
            Globals.employees.init();
            this.DialogResult = true;
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private async void ChildWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // Load names into the combo box
            await Globals.db.GetEmployeeObjects("Active=0 order by LastName, FirstName, MiddleInitial");
            foreach (ServiceReferenceOpenRPOS.Employee emp in Globals.db.EmployeeRecords)
            {
                cmbNames.Items.Add(emp.col_LastName + ", " + emp.col_FirstName + " " + emp.col_MiddleInitial);
            }
            // Select the first name in the list
            cmbNames.SelectedIndex = 0;
        }


    }
}

